package cc.ewell.esb.authenticating;

import cc.ewell.esb.authenticating.util.HttpURLConnectionUtil;
import java.io.IOException;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.UUID;


public class Call {
    private static Logger log = LoggerFactory.getLogger(Call.class);

    public static String callMethod(String method, String paramXml) {
        long startTime = System.currentTimeMillis();
        String traceId = UUID.randomUUID().toString().replace("-", "");
        log.info("TraceId: {}|method: {}|paramXml: {}", traceId, method, null);

        Call call = new Call();
        String out = call.doCallMethod(method, paramXml, traceId);
        log.info("TraceId: {}|OutPara: {}|Duration: {}ms", traceId, out, System.currentTimeMillis() - startTime);
        return out;
    }

    public static String callMethod(String method, String paramXml, String msgId) {
        long startTime = System.currentTimeMillis();
        log.info("TraceId: {}|method: {}|paramXml: {}", msgId, method, null);

        Call call = new Call();
        String out = call.doCallMethod(method, paramXml, msgId);
        log.info("TraceId: {}|OutPara: {}|Duration: {}ms", msgId, out, System.currentTimeMillis() - startTime);
        return out;
    }

    public String doCallMethod(String method, String paramXml, String traceId) {
        log.trace("TraceId: {}|method: {}|paramXml: {}", traceId, method, paramXml);
        long startTime = System.currentTimeMillis();

        String str = null;
        String url = "http://www.esb-auth.com:7003/integration-esb-authenticating-server/integration/interfaces/reqreply.do";

        HttpURLConnectionUtil util = new HttpURLConnectionUtil();
//        str = util.post(url, method, paramXml);
        str = util.post(url, method, paramXml, traceId);


//        log.debug("callMethod耗时  - {}ms", Long.valueOf(System.currentTimeMillis() - startTime));
        log.trace("TraceId: {}|OutPara: {}|Duration: {}ms", traceId, str, System.currentTimeMillis() - startTime);
        return str;
    }

    public String doCallMethod(String method, String paramXml) {
        long startTime = System.currentTimeMillis();
        String str = null;
        String url = "http://www.esb-auth.com:7003/integration-esb-authenticating-server/integration/interfaces/reqreply.do";

        HttpURLConnectionUtil util = new HttpURLConnectionUtil();
        str = util.post(url, method, paramXml);


        log.debug("callMethod耗时  - {}ms", Long.valueOf(System.currentTimeMillis() - startTime));
        return str;
    }

    public static String getParam(String paramXml) {
        if (StringUtils.isEmpty(paramXml)) {

            try {


                paramXml = IOUtils.toString(Call.class.getResourceAsStream("/推送格式-EMR.xml"));
            } catch (IOException e) {
                log.debug("1.{} - {}", Thread.currentThread(), paramXml);
            }
        }

        return paramXml;
    }

    public static String getParam() {
        return getParam(null);
    }


    public static void main(String[] args) {
//                if(true){
//            callMethod("authPubSub", "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
//                    "<ESBEntry><AccessControl><UserName>ZYHIS</UserName><Password>ZYHIS123</Password>" +
//                    "<SysFlag>1</SysFlag><Fid>PS35001</Fid></AccessControl><MessageHeader><Fid>PS35001</Fid>" +
//                    "<SourceSysCode>S12</SourceSysCode><ReturnFlag>-1</ReturnFlag>" +
//                    "<TargetSysCode>S00</TargetSysCode><MsgDate/></MessageHeader><MsgInfo>" +
//                    "<Msg id=\"\" lastUpdate=\"\" action=\"update\"><INHOSP_INDEX_NO>20022419</INHOSP_INDEX_NO>" +
//                    "<MR_NO>10013301</MR_NO><ANAMNESIS_NO/><VISIT_CARD_NO>7123498573</VISIT_CARD_NO>" +
//                    "<INHOSP_NUM/><INHOSP_NO>20022419</INHOSP_NO><PAT_INDEX_NO>7123498573</PAT_INDEX_NO>" +
//                    "<ORDERLIST><HIS_ORDER_NO>11892417</HIS_ORDER_NO><HIS_ORDER_SUB_NO>1</HIS_ORDER_SUB_NO>" +
//                    "<ORDER_NO>17551877532130436154</ORDER_NO><ORDER_GROUP_NO>17551877532130436154</ORDER_GROUP_NO>" +
//                    "<ORDER_PLAN_BEGIN_DATE>2025-08-15 00:09:00</ORDER_PLAN_BEGIN_DATE><ORDER_PLAN_END_DATE/>" +
//                    "<ORDER_ORDER_DATE>2025-08-15 00:09:17</ORDER_ORDER_DATE>" +
//                    "<ORDER_BEGIN_DATE>2025-08-15 00:09:17</ORDER_BEGIN_DATE>" +
//                    "<ORDER_PROOF_DATE>2025-08-15 00:09:17</ORDER_PROOF_DATE><ORDER_CANCEL_DATE/>" +
//                    "<ORDER_STOP_DATE/><ORDER_EXECUT_DATE>2025-08-15 00:09:00</ORDER_EXECUT_DATE>" +
//                    "<ORDER_END_DATE/><ORDER_ITEM_TYPE_CODE>HL</ORDER_ITEM_TYPE_CODE>" +
//                    "<ORDER_ITEM_TYPE_NAME>护理</ORDER_ITEM_TYPE_NAME><ORDER_CATEG_CODE>1</ORDER_CATEG_CODE>" +
//                    "<ORDER_CATEG_NAME>长期医嘱</ORDER_CATEG_NAME><ORDER_ITEM_CODE>HLL000109</ORDER_ITEM_CODE>" +
//                    "<ORDER_ITEM_NAME>Ⅱ级护理</ORDER_ITEM_NAME><DRUG_SPEC/><DOSE_WAY_CODE/><DOSE_WAY_NAME/>" +
//                    "<DRUG_USE_ONE_DOSAGE>1</DRUG_USE_ONE_DOSAGE><DRUG_USE_ONE_DOSAGE_UNIT/>" +
//                    "<DRUG_USE_FREQUENCY_CODE/><DRUG_USE_FREQUENCY_NAME>qd</DRUG_USE_FREQUENCY_NAME>" +
//                    "<DRUG_FORM_CODE/><DRUG_FORM_NAME/><DRUG_UNIT/><DRUG_UNIT_PRICE/><DRUG_ABBREV/>" +
//                    "<DRUG_DESCR/><DRUG_AMOUNT/><ORDER_DURATION/><ORDER_DURATION_UNIT/>" +
//                    "<ORDER_EXECUT_STATUS_CODE>3</ORDER_EXECUT_STATUS_CODE>" +
//                    "<ORDER_EXECUT_STATUS_NAME>已校对</ORDER_EXECUT_STATUS_NAME><BASE_AUX_DRUG_FLAG/>" +
//                    "<VALUATION_FLAG/><VALUATION_DATE/><DR_ENTRUST/><NOTE/>" +
//                    "<FIRST_DAY_EXECUT_NUM>1</FIRST_DAY_EXECUT_NUM><LAST_DAY_EXECUT_NUM/><BABY_FLAG>0</BABY_FLAG>" +
//                    "<INVALID_FLAG/><SELF_OWNED_DRUG_FLAG>0</SELF_OWNED_DRUG_FLAG><DISCHARGE_ORDER_FLAG/>" +
//                    "<ORDER_OPEN_DEPT_INDEX_NO/><ORDER_OPEN_DEPT_CODE>03310141</ORDER_OPEN_DEPT_CODE>" +
//                    "<ORDER_OPEN_DEPT_NAME>耳鼻喉科耳病区</ORDER_OPEN_DEPT_NAME><ORDER_OPEN_DR_INDEX_NO/>" +
//                    "<ORDER_OPEN_DR_CODE>8781</ORDER_OPEN_DR_CODE><ORDER_OPEN_DR_NAME>惠阳</ORDER_OPEN_DR_NAME>" +
//                    "<ORDER_PROOF_DR_INDEX_NO/><ORDER_PROOF_DR_CODE>8781</ORDER_PROOF_DR_CODE>" +
//                    "<ORDER_PROOF_DR_NAME>惠阳</ORDER_PROOF_DR_NAME><ORDER_CANCEL_DR_INDEX_NO/>" +
//                    "<ORDER_CANCEL_DR_CODE/><ORDER_CANCEL_DR_NAME/><ORDER_EXECUT_DR_INDEX_NO/>" +
//                    "<ORDER_EXECUT_DR_CODE/><ORDER_EXECUT_DR_NAME/><ORDER_STOP_DR_INDEX_NO/><ORDER_STOP_DR_CODE/>" +
//                    "<ORDER_STOP_DR_NAME/><ORDER_RECORD_DR_INDEX_NO/><ORDER_RECORD_DR_CODE/><ORDER_RECORD_DR_NAME/>" +
//                    "<MEDICATION_FREQUENCY_COUNTER/><MEDICATION_FREQUENCY_INTERVAL/><MEDICATION_FREQUENCY_UNIT/>" +
//                    "<MEDICATION_FREQUENCY_DETAIL/><MEDICATION_PERFORM_SCHEDULE/><ORDER_OPEN_WARD_NAME/>" +
//                    "<ORDER_CHECK_TIME/><ORDER_CHECKER_SIGN/><ORDER_CHECKER_ID/><ORDER_CHECKER_NAME/>" +
//                    "<STOPORDER_CHECK_TIME/><STOPORDER_CHECKER_NAME/><STOPORDER_CHECKER_ID/><DRUG_REVIEW/>" +
//                    "<DRUG_REVIEW_INFO/><ORDER_DISPENSE_DRUG_ATTR/></ORDERLIST>" +
//                    "<PRESTORE_ORDER_FLAG>0</PRESTORE_ORDER_FLAG><DIAG_CODE/><DIAG_NAME/><RECORD_DATE/>" +
//                    "<UPDATE_DATE/></Msg></MsgInfo></ESBEntry>");
//            return;
//        }
        Call call = new Call();
        String str = callMethod("authenticateReqResp", getParam());
        log.debug("{}", str);
    }
}


/* Location:              C:\Users\taoo6\Desktop\integrationEsbAuthenticating-client-1.0.jar!\cc\ewell\esb\authenticating\Call.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       1.1.3
 */